﻿package mortal.game.view.closedBetaGiftBagNew.cellRender
{
    import com.gengine.resource.*;
    import com.mui.controls.*;
    import com.mui.core.*;
    import flash.events.*;
    import flash.geom.*;
    import mortal.component.gconst.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.view.closedBetaGiftBagNew.group.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.display.*;
    import mortal.mvc.core.*;

    public class ClosedbetaLevelGiftCellRender extends GCellRenderer
    {
        private var _getBtn:GLoadingButton;
        private var _cellBg:GImageBitmap;
        private var _bmpText1:GImageBitmap;
        private var _bmpText2:GImageBitmap;
        private var _bmpText3:GImageBitmap;
        private var _diamonIcon:GImageBitmap;
        private var _bmpNumText:BitmapNumberText;
        private var _bmpHasReceive:GBitmap;
        private var _group:ClosedBetaLevelGiftGroup;

        public function ClosedbetaLevelGiftCellRender()
        {
            return;
        }// end function

        private function onClickGetBtn(event:MouseEvent) : void
        {
            if (!this._group)
            {
                return;
            }
            Dispatcher.dispatchEvent(new DataEvent(EventName.ClosedBetaLevelGiftRequest, this._group.level));
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._cellBg = UIFactory.gImageBitmap(ImagesConst.closedBetaGiftBagNewCellBgOn, 0, 0, this);
            this._bmpText1 = UIFactory.gImageBitmap(ImagesConst.closedBetaGiftBagNewText1, 20, 40, this);
            this._bmpText2 = UIFactory.gImageBitmap(ImagesConst.closedBetaGiftBagNewText2, 20, 40, this);
            this._bmpText3 = UIFactory.gImageBitmap(ImagesConst.closedBetaGiftBagNewText3, 20, 40, this);
            this._diamonIcon = UIFactory.gImageBitmap(ImagesConst.closedBetaGiftBagNewDiamondOn, 54, 80, this);
            this._bmpNumText = UIFactory.bitmapNumberText(96, 11, "EquipToolTipCombat.png", 14, 16, -2, this, 10, BitmapNumberText.Mid);
            this._bmpNumText.text = "0";
            this._getBtn = UIFactory.gLoadingButton(ResFileConst.RectGetBtn, 50, 150, 68, 25, this);
            this._getBtn.addEventListener(MouseEvent.CLICK, this.onClickGetBtn);
            this._bmpHasReceive = UIFactory.gBitmap("", 50, 100, this);
            LoaderHelp.addResCallBack(ResFileConst.lineOn, this.onResLoadCompl);
            Dispatcher.addEventListener(EventName.ClosedBetaLevelGiftTake, this.onClosedBetaGiftBagFlyToPack);
            return;
        }// end function

        private function onResLoadCompl() : void
        {
            this._bmpHasReceive.bitmapData = GlobalClass.getBitmapData(ImagesConst.lineOnGetRewardFlag);
            return;
        }// end function

        override public function set data(param1:Object) : void
        {
            super.data = param1;
            this._group = param1 as ClosedBetaLevelGiftGroup;
            var _loc_2:* = this._group.textType;
            this._bmpNumText.text = this._group.level.toString();
            this.resetShow();
            if (_loc_2 == 1)
            {
                this._bmpText1.visible = true;
            }
            else if (_loc_2 == 2)
            {
                this._bmpText2.visible = true;
            }
            else if (_loc_2 == 3)
            {
                this._bmpText3.visible = true;
            }
            if (this._group.receiveType == ClosedBetaBaseGroup.CanReceive)
            {
                this.SetCanReceive();
            }
            else if (this._group.receiveType == ClosedBetaBaseGroup.HasReceive)
            {
                this.SetHasReceive();
            }
            else
            {
                this.SetNullReceive();
            }
            return;
        }// end function

        private function SetCanReceive() : void
        {
            this._getBtn.visible = true;
            this._getBtn.filterEnabled = true;
            EffectManager.glowFilterReg(this._getBtn);
            this._bmpHasReceive.visible = false;
            this._diamonIcon.filters = [];
            return;
        }// end function

        private function SetNullReceive() : void
        {
            this._getBtn.visible = true;
            this._getBtn.filterEnabled = false;
            EffectManager.glowFilterUnReg(this._getBtn);
            this._bmpHasReceive.visible = false;
            this._diamonIcon.filters = [FilterConst.colorFilter3];
            return;
        }// end function

        private function SetHasReceive() : void
        {
            this._getBtn.visible = false;
            EffectManager.glowFilterUnReg(this._getBtn);
            this._bmpHasReceive.visible = true;
            this._diamonIcon.filters = [FilterConst.colorFilter3];
            return;
        }// end function

        private function resetShow() : void
        {
            this._bmpText1.visible = false;
            this._bmpText2.visible = false;
            this._bmpText3.visible = false;
            return;
        }// end function

        private function onClosedBetaGiftBagFlyToPack(event:DataEvent) : void
        {
            if (isDisposed)
            {
                return;
            }
            if (this._diamonIcon.bitmapData == null)
            {
                return;
            }
            var _loc_2:* = event.data as int;
            if (_loc_2 != this._group.level)
            {
                return;
            }
            var _loc_3:* = this._diamonIcon.localToGlobal(new Point(0, 0));
            FlyToNavbarTool.flyToBackPack(this._diamonIcon.bitmapData, _loc_3);
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            LoaderHelp.removeResEvent(ResFileConst.lineOn, this.onResLoadCompl);
            this._getBtn.removeEventListener(MouseEvent.CLICK, this.onClickGetBtn);
            this._cellBg.dispose(param1);
            this._bmpText1.dispose(param1);
            this._bmpText2.dispose(param1);
            this._bmpText3.dispose(param1);
            this._diamonIcon.dispose(param1);
            this._bmpNumText.dispose(param1);
            this._getBtn.dispose(param1);
            this._bmpHasReceive.dispose(param1);
            this._cellBg = null;
            this._bmpText1 = null;
            this._bmpText2 = null;
            this._bmpText3 = null;
            this._diamonIcon = null;
            this._bmpNumText = null;
            this._getBtn = null;
            this._bmpHasReceive = null;
            return;
        }// end function

    }
}
